package cn.iocoder.yudao.module.wms.dal.mysql.warehouse;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.wms.dal.dataobject.warehouse.PositionDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 库位 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface PositionMapper extends BaseMapperX<PositionDO> {

    default PageResult<PositionDO> selectPage(PageParam reqVO, Long warehouseId) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PositionDO>()
            .eq(PositionDO::getWarehouseId, warehouseId)
            .orderByDesc(PositionDO::getId));
    }

    default int deleteByWarehouseId(Long warehouseId) {
        return delete(PositionDO::getWarehouseId, warehouseId);
    }

    default PositionDO selectByCode(Long warehouseId, String code) {
        return selectOne(new LambdaQueryWrapperX<PositionDO>()
                .eqIfPresent(PositionDO::getWarehouseId, warehouseId)
                .eqIfPresent(PositionDO::getCode, code));
    }

    default List<PositionDO> selectListByWarehouseId(Collection<Long> warehouseIds) {
        return selectList(new LambdaQueryWrapperX<PositionDO>()
                .inIfPresent(PositionDO::getWarehouseId, warehouseIds));
    }

    default List<PositionDO> selectList(Collection<Long> ids) {
        return selectList(new LambdaQueryWrapperX<PositionDO>()
                .inIfPresent(PositionDO::getId, ids));
    }

    default PositionDO selectFirstByWarehouse(Long id) {
        return selectOne(new LambdaQueryWrapperX<PositionDO>()
                .eqIfPresent(PositionDO::getWarehouseId, id)
                .last("limit 1"));
    }
}